//
//  Video.swift
//  Tiktok
//
//  Created by xmd on 10/3/20.
//

import Foundation
import UIKit
import Combine
import SwiftUI
import AVKit

class VideoPlayerPageVM: ObservableObject, Identifiable {
    @Published var isPaused = false
    @Published var isLiked = false
    
    var index: Int
    var aweme: Aweme
    var id: Int { index }
    
    init(index : Int) {
        self.index = index
        self.aweme = awemeData.aweme_list[index]
    }
    
    var videoUrl: String {
        aweme.video.playAddr.urlList.first!
    }
    
    var avatarImageUrl: String {
        aweme.author.avatarThumb.urlList.first!
    }
    
    var musicCoverImageUrl : String {
        aweme.music!.coverThumb.urlList.first!
    }
    
    var diggCount: Int {
        aweme.statistics.diggCount
    }
    
    var commentCount: Int {
        aweme.statistics.commentCount
    }
    
    var shareCount: Int {
        aweme.statistics.shareCount
    }
    
    var nickName: String {
        aweme.author.nickName
    }
    
    var desc: String {
        aweme.desc ?? ""
    }
    
    var musicDesc: String {
        (aweme.music?.title ??  "") + " - " + (aweme.music?.album ?? "")
    }
    
    func playOrPause() {
        withAnimation(.easeIn(duration: 0.1)) {
            isPaused.toggle()
        }
    }
}
